/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tesam.gedeon.dao.impl;

import com.tesam.gedeon.dao.DistrictDao;
import com.tesam.gedeon.entity.District;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Sistema
 */
@Repository
public class DistrictDaoImpl extends SimpleJdbcDaoSupport  implements DistrictDao {

    @Autowired
    public DistrictDaoImpl(DataSource dataSource) {
        setDataSource(dataSource);
    }
    
    @Override
    public List<District> getDistrictByProvinceAndDepartmentAndCountry(District district) {
        List<District> result = new ArrayList();
            try{

                result = getJdbcTemplate().query("select id , code_country , code_department , code_province , code , "
                        + "name , zipcode from district  " +
                          "where deleted = 0 and upper(code_country) = '"+district.getCountry().getCode()+"' "
                        + "and upper(code_department) = '"+district.getDepartment().getCode()+"' "
                        + "and upper(code_province) = '"+district.getProvince().getCode()+"' " 
                     , new BeanPropertyRowMapper<District>(District.class));
            }catch(Exception e){
                System.out.println("getDistrictByProvinceAndDepartmentAndCountry : "+e.getMessage());
            }
        return result ;
    }
    
}
